    
import java.sql.*;
import java.util.Calendar;
import javax.swing.JOptionPane;




public class Assignment {
    
    public int roomID;
    public int studentID;
    public int year;
    public boolean forTerm1;
    public boolean forTerm2;
    public boolean forTerm3;
    
    private Connection connect;
    
    
    
    public Assignment(int roomID, int studentID, int year, boolean forTerm1, 
            boolean forTerm2, boolean forTerm3) {
        this.roomID = roomID;
        this.studentID = studentID;
        this.year = year;
        this.forTerm1 = forTerm1;
        this.forTerm2 = forTerm2;
        this.forTerm3 = forTerm3;
    }
    public Assignment(int roomID, int studentID){
        this.roomID = roomID;
        this.studentID = studentID;
        this.year = Calendar.getInstance().get(Calendar.YEAR);
        this.forTerm1 = true;
        this.forTerm2 = true;
        this.forTerm3 = true;
    }
    
    
   //Insert new entry to db
    public boolean addToDB(Connection connect){
        
        try {
            String addQuery = "INSERT INTO DORMS.assignment (roomID, studentID, year,"
                    + "forTerm1, forTerm2, forTerm3) VALUES (?,?,?,?,?,?)";
            PreparedStatement addStmt = connect.prepareStatement(addQuery);
            addStmt.setInt(1, roomID);
            addStmt.setInt(2, studentID);
            addStmt.setInt(3, year);
            addStmt.setBoolean(4, forTerm1);
            addStmt.setBoolean(5, forTerm2);
            addStmt.setBoolean(6, forTerm3);
            addStmt.execute();
            
            return true;
            
        }catch (Exception ex){
            JOptionPane.showMessageDialog(null,
                    "Unable to add to database");
             
        }
        return false;
        
        
    }
    
    public static boolean checkFull(int roomID, ResultSet result, Connection connect){
        Room toCheck = new Room(roomID,connect);
        int max = toCheck.type + 1;
        int counter = 0; 
        try{
            while(result.next()){
                counter++;
            }
            if(counter >= max)
                return true;
        }catch(Exception e){

        }

        return false;
    }
    
}
